package com.svpino.netflix.parsers;

import java.io.StringReader;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;

import com.svpino.netflix.ProxyImpl;
import com.svpino.netflix.Response;

public abstract class OldParser {

	private final ProxyImpl connection;

	public OldParser(ProxyImpl connection) {
		this.connection = connection;
	}

	protected Element request(String url) {
		try {
			Response response = getConnection().request(url);

			DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
			StringReader reader = new StringReader(response.getXmlContent());
			InputSource inputSource = new InputSource(reader);
			Document document = documentBuilderFactory.newDocumentBuilder().parse(inputSource);
			reader.close();

			return document.getDocumentElement();
		}
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;
	}

	protected ProxyImpl getConnection() {
		return this.connection;
	}

}
